#include <iostream>
#include <vector>
using namespace std;

void to_palindromic(vector<int> list, int &num)
{
    if (list.size() <= 1)
        return;

    auto first = list.begin();
    auto rear = list.end() - 1;

    if (*first == *rear)
    {
        // 如果先删除first会越界
        list.erase(rear);
        list.erase(first);
        to_palindromic(list, num);
    }
    else if (*first < *rear)
    {
        *(first + 1) += *first;
        list.erase(first);
        to_palindromic(list, ++num);
    }
    else
    {
        *(rear - 1) += *rear;
        list.erase(rear);
        to_palindromic(list, ++num);
    }
}

int main()
{
    int num = 0;
    vector<int> list{1, 1, 1, 3};
    to_palindromic(list, num);
    cout << num << endl;
    return 0;
}